<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'mortgage.label', default: 'Mortgage')}"/>
    <title>抵押贷款</title>
    <style>
    .table>tbody>tr>td{
        vertical-align: middle;
    }
    @media screen and (min-width:1900px) and (max-width:1920px) {
        .flex{
            display: flex;justify-content: center;align-items: center;
        }
    }
    .select2-container .select2-choices .select2-search-field input,.select2-container .select2-choice,.select2-container .select2-choices{

        color: #999;
    }
    </style>
</head>

<body class="fixed-navbar fixed-sidebar">

<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right navFloatRight">
                <ol class="hbreadcrumb breadcrumb">
                    <li>
                        <span>CINDATA PLS</span>
                    </li>
                    <li class="active">
                        <span>贷款</span>
                    </li>
                </ol>
            </div>
        </div>
    </div>
</div>

<g:if test="${params?.message}">
    <div class="message alert alert-info" role="status">${params?.message}</div>
</g:if>

<g:if test="${flash.message}">
    <div class="message alert alert-info" role="status">${flash.message}</div>
</g:if>

<div class="content animate-panel">
    <div class="row">
        <g:form method="POST" action="index" class="form-horizontal searchForm" role="form" id="form" >
            <div class="hpanel hblue">
                <div class="panel-heading">
                    <div class="panel-tools">
                        <button class="btn btn-primary btn-xs" type="submit" onclick=""><i class="fa fa-search"></i> 查询</button>
                        <button class="btn btn-warning2 btn-xs" type="button" id="resetBtn">
                            <i class="fa fa-times"></i> 重置</button>
                        <button class="btn btn-primary btn-xs" type="button" href="" id="packBtn" onclick="openModal(this);">
                            资产打包</button>
                    </div>
                    查询
                </div>
                <div class="panel-body seach-group" id="bug1">
                    %{--第一行--}%
                    <div class="row">
                        <div class="form-group col-sm-4">
                            <label for="city" class="col-sm-3 control-label">城市</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="city" id="city"
                                          from="${com.cindata.City.findAllByNameInList(new com.cindata.ComponentService().evaluate(com.cindata.Component.findByCode('showCity')), [sort: 'name', order: 'asc'])}"
                                          valueMessagePrefix="status" optionKey="zoneNumber" optionValue="name"
                                          value="${params?.city}"
                                          noSelection="${["-1": '请选择城市']}"/>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label" for="loansDuration">贷款时长</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="loansDuration" id="loansDuration"
                                          from="${com.cindata.dimension.YearLimitDimension.list()}"
                                          valueMessagePrefix="status" optionKey="label" optionValue="label"
                                          value="${params?.loansDuration}"
                                          noSelection="${["": '请选择贷款时长']}"/>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">贷款金额</label>
                            <div class="col-sm-7 input-group ">
                                <input type="text" class=" form-control " placeholder="请输入下限" maxlength="6"
                                       id="loansAmountStart" value="${params?.loansAmountStart}" name="loansAmountStart" />
                                <span class="input-group-addon">至</span>
                                <input type="text" class=" form-control " placeholder="请输入上限" maxlength="6"
                                       id="loansAmountEnd" value="${params?.loansAmountEnd}" name="loansAmountEnd" />
                            </div>
                            <div class="col-sm-2 p-t-xss">
                                万元
                            </div>
                        </div>
                    </div>
                    %{--第二行--}%
                    <div class="row">
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">贷款状态</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="mortgageStatus" id="mortgageStatus"
                                          from="${com.cindata.dictionary.MortgageStatusDict.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.mortgageStatus}"
                                          noSelection="${["": '请选择贷款状态']}"/>
                            </div>
                        </div>

                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label" for="riskWarningLevel">关注等级</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="riskWarningLevel" id="riskWarningLevel"
                                          from="${com.cindata.RiskWarningLevel.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.riskWarningLevel}"
                                          noSelection="${["": '请选择关注等级']}"/>
                            </div>
                        </div>
                        
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">贷款余额</label>
                            <div class="col-sm-7  input-group">
                                <input type="text" class=" form-control "
                                       placeholder="请输入下限" id="loansBalanceStart" maxlength="6"
                                       value="${params?.loansBalanceStart}" name="loansBalanceStart" />
                                <span class="input-group-addon">至</span>
                                <input type="text" class="form-control " placeholder="请输入上限" maxlength="6"
                                       id="loansBalanceEnd"  value="${params?.loansBalanceEnd}" name="loansBalanceEnd" />
                            </div>
                            <div class="col-sm-2 p-t-xss">
                                万元
                            </div>
                        </div>
                    </div>
                    %{--第三行--}%
                    <div class="row">
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">受理网点</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="accountId" id="accountId"
                                          from="${accountManageAccountList}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.accountId}"
                                          noSelection="${["": '请选择受理网点名称']}"/>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label" for="loansDuration">抵押类型</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="mortgageType" id="mortgageType"
                                          from="${com.cindata.dictionary.MortgageType.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.mortgageType}"
                                          noSelection="${["": '请选择抵押类型']}"/>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                        <label class="col-sm-3 control-label">放款时间</label>
                        <div class="col-sm-9 input-daterange input-group p-r-n"  id="datepicker" style="width: 75%;">
                            <input type="text" class=" form-control " placeholder="请选择放款时间"
                                   value="${params?.startDateStart}" name="startDateStart" id="startDateStart" style="text-align: left" />
                            <span class="input-group-addon">至</span>
                            <input type="text" class=" form-control " placeholder="请选择结束时间"
                                   value="${params?.startDateEnd}" name="startDateEnd" id="startDateEnd" style="text-align: left" />
                        </div>
                    </div>
                    </div>
                    %{--第四行--}%
                    <div class="row">

                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label" for="loansDuration">贷款编号</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="serialNumber" id="serialNumber" value="${params?.serialNumber}" placeholder="请输入贷款编号">
                            </div>
                        </div>

                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label" for="loansDuration">贷款类型</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="mortgageCategory" id="mortgageCategory"
                                          from="${com.cindata.dictionary.MortgageCategory.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.mortgageCategory}"
                                          noSelection="${["": '请选择贷款类型']}"/>
                            </div>
                        </div>

                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label" for="loansDuration">贷款方式</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="mortgagePattern" id="mortgagePattern"
                                          from="${com.cindata.dictionary.MortgagePattern.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.mortgagePattern}"
                                          noSelection="${["": '请选择贷款方式']}"/>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </g:form>
    </div>

    <div class="row">
        <div class="hpanel hgreen">
            <div class="panel-heading">
                <div class="panel-tools">
                    <!-- <button class="btn btn-warning2 btn-xs" type="submit" onclick="searchMap()"><i class="fa fa-map-marker"></i> 查看地图</button> -->
                    <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                </div>
                &nbsp;&nbsp;
            </div>

            <div class="panel-body no-padding">
                <div class="table-responsive">
                    <table cellpadding="1" cellspacing="1" class="table table-striped table-bordered table-hover text-center" id="esateTable">
                        <thead>
                        <tr>
                            <g:sortableColumn property="serialNumber" title="贷款编号" class="col-md-1 text-center" params="${params}"/>
                            <g:sortableColumn property="mortgageCategory" title="贷款类型" class="col-md-1 text-center" params="${params}"/>
                            <g:sortableColumn property="city" title="城市" class="col-md-1 text-center" params="${params}"/>
                            <g:sortableColumn property="guaranteeInstitution" title="担保机构" class="col-md-1 text-center" params="${params}"/>
                            <g:sortableColumn property="mortgageType" title="抵押类型" class="col-md-1 text-center" params="${params}"/>
                            <g:sortableColumn property="mortgagePattern" title="贷款方式" class="col-md-1 text-center" params="${params}"/>
                            <g:sortableColumn property="mortgageStatus" title="贷款状态" class=" col-md-1 text-center" params="${params}"/>
                            <g:sortableColumn property="riskWarningLevel" title="关注等级" class=" col-md-1 text-center" params="${params}"/>
                            <g:sortableColumn property="loansAmount" title="贷款金额"  class="col-md-1 text-center" params="${params}"/>
                            <g:sortableColumn property="loansBalance" title="贷款余额" class="col-md-1 text-center"  params="${params}"/>
                            <g:sortableColumn property="startDate" title="放款时间" class="col-md-1 text-center"  params="${params}"/>
                            <g:sortableColumn property="account" title="受理网点" class=" col-md-1 text-center" params="${params}"/>
                        </tr>
                        </thead>
                        <tbody>
                        <g:each in="${mortgageList}">
                            <tr>
                                <td><g:link style="color: #3498DB" class="firstTd" id="${it?.id}" action="show">${it?.serialNumber?it?.serialNumber:'-'}</g:link></td>
                                <td>${it?.mortgageCategory? it?.mortgageCategory?.name : '-'}</td>
                                <td>${it?.account?.city?.name ? it?.account?.city?.name : '-'}</td>
                                <td>${it?.guaranteeInstitution? it?.guaranteeInstitution?.name : '-'}</td>
                                <td>${it?.mortgageType? it?.mortgageType?.name : '-'}</td>
                                <td>${it?.mortgagePattern? it?.mortgagePattern?.name : '-'}</td>
                                <td>${it?.mortgageStatus?.name ? it?.mortgageStatus?.name : '-'}</td>
                                <td>${it?.riskWarningLevel ? it?.riskWarningLevel?.name : '-'}</td>
                                <td>${it?.loansAmount ? it?.loansAmount : ''}</td>
                                <td>${it?.loansBalance ? it?.loansBalance : '-'}</td>
                                <td>
                                    <g:if test="${it?.startDate}">
                                        <g:formatDate date="${it?.startDate}" format="yyyy-MM-dd"></g:formatDate>
                                    </g:if>
                                    <g:else>
                                        -
                                    </g:else>
                                </td>
                                <td>${it?.account.name?it?.account.name:'-'}</td>
                            </tr>
                        </g:each>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="panel-footer">
                <div class="pagination">
                    <g:paginate action="index" total="${mortgageCount ?: 0}" params="${params}"/>
                </div>
            </div>
        </div>
    </div>
</div>

%{--弹框--}%
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="color-line" style="background: #3498db"></div>
            <div class="modal-header text-center">
                <h4 class="modal-title">该批次记录${this.mortgageCount}条，是否确认打包？</h4>
            </div>
            <div class="modal-body">
                <g:form class="form-horizontal packForm" controller="abnormalMortgageBatch" action="batchSave" method="post">
                    <div class="modal-body">
                      <div class="form-group">
                          <label class="col-md-3 control-label is-required">名称</label>
                          <div class="col-md-9">
                              <div>
                                  <input type="text" class="form-control" name="name" id="name" value="${abnormalMortgageBatch?.name}"/>
                              </div>

                          </div>
                      </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label is-required">处置方式</label>
                            <div class="col-md-9">
                              <g:select class="form-control" name="disposeMethod" id="disposeMethod"
                                        from="${com.cindata.AbnormalMortgageBatch.constrainedProperties.disposeMethod.inList}"
                                        valueMessagePrefix="status"
                                        value="${abnormalMortgageBatch?.disposeMethod}"
                                        noSelection="${["": '请选择处置方式']}"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label is-required">工作流</label>
                            <div class="col-md-9">
                                <g:select class="form-control" name="workflow" id="workflow" from="${com.cindata.Workflow.findAllByType(com.cindata.dictionary.WorkflowType.findByName('资产包'))}" optionValue="name" optionKey="id" value="${params.workflow}" noSelection="${['': '请选择工作流']}"/>
                            </div>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal" id="closeModal">关闭</button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal" id="confirm">打包</button>
                    </div>
                </g:form>
            </div>
        </div>
    </div>
</div>

<g:javascript>
    function searchMap() {
        var city = $("#city").val();
        if(city=="-1"){
            toastr.error('请选择城市');
            return
        }
        window.location.href="/newMap/cluster?currentMap=clusterMap&city="+$("#city").val()+"&district="+$("#district").val()+"&communityId="+$("#communityId").val();
    }
    function show(id){
        var url = window.location.origin+"/mortgage/show?id="+id;
        window.open(url);
    }
    $(function () {
        $('#datepicker').datepicker({
            language: 'zh-CN'
        });
        $("#datepicker").on("changeDate", function(event) {
            $("#my_hidden_input").val(
                    $("#datepicker").datepicker('getFormattedDate')
            )
        });

        $('.input-group.date').datepicker({ });
        $('.input-daterange').datepicker({ });
    });

    //重置按钮
    $("#resetBtn").click(function () {
        $("#communityId").val("");
        $("#s2id_city span:first").html("请选择城市");
        $("#city").val("");
        $("#s2id_loansDuration span:first").html("请选择贷款时长");
        $("#loansDuration").val("");
        $("#loansAmountStart").val("");
        $("#loansAmountEnd").val("");
        $("#loansBalanceStart").val("");
        $("#loansBalanceEnd").val("");
        $("#s2id_mortgageStatus span:first").html("请选择贷款状态");
        $("#mortgageStatus").val("");
        $("#s2id_isNonPerformingLoan span:first").html("请选择是否不良");
        $("#isNonPerformingLoan").val("");
        $("#startDateEnd").val("");
        $("#startDateStart").val("");
        $('#s2id_accountId span:first').html('请选择受理网点名称');
        $('#accountId').val("");
        $('#s2id_mortgageType span:first').html('请选择抵押类型');
        $('#mortgageType').val("");
        $('#s2id_mortgagePattern span:first').html('请选择贷款方式');
        $('#mortgagePattern').val("");
        $('#s2id_mortgageCategory span:first').html('请选择贷款类型');
        $('#mortgageCategory').val("");
        $('#s2id_riskWarningLevel span:first').html('请选择关注等级');
        $('#riskWarningLevel').val("");
        $('#serialNumber').val("");
    });

    //弹出模态框
    function openModal(obj) {
        $('#myModal').modal('show');
    }

    $("#confirm").click(function () {
        var name = $("#name").val();
        var disposeMethod = $("#disposeMethod").val();
        var workflow = $("#workflow").val();
        if(!name){
            toastr.error("请输入名称！");
            return
        }
        if(!disposeMethod){
            toastr.error("请选择处置方式！");
            return
        }
        if(!workflow){
            toastr.error("请选择工作流！");
            return
        }
        var searchDiv = $(".searchForm").html();
        $(".packForm").append(searchDiv);
        $(".packForm").submit();
    });
    //关闭模态框清空
    $("#closeModal").click(function () {
    });

</g:javascript>

</body>
</html>
